package com.cursor.config;

import com.cursor.entity.CursorAccount;
import com.cursor.entity.LicenseKeys;
import com.cursor.entity.Notification;
import com.cursor.repository.CursorAccountRepository;
import com.cursor.repository.LicenseKeysRepository;
import com.cursor.repository.NotificationRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class DataInitializer implements CommandLineRunner {

    private final NotificationRepository notificationRepository;
    private final LicenseKeysRepository licenseKeysRepository;
    private final CursorAccountRepository cursorAccountRepository;

    @Override
    public void run(String... args) {
        // 初始化通知数据
        if (notificationRepository.count() == 0) {
            Notification notification1 = new Notification();
            notification1.setMessage("欢迎使用Cursor Switcher! 点击了解更多");
            notification1.setLinkUrl("https://example.com");
            notificationRepository.save(notification1);

            Notification notification2 = new Notification();
            notification2.setMessage("新版本已发布，点击查看更新内容");
            notification2.setLinkUrl("https://example.com/update");
            notificationRepository.save(notification2);

            Notification notification3 = new Notification();
            notification3.setMessage("使用教程已更新");
            notification3.setLinkUrl("#");
            notificationRepository.save(notification3);

            Notification notification4 = new Notification();
            notification4.setMessage("重要通知：系统维护");
            notification4.setLinkUrl("https://example.com/notice");
            notificationRepository.save(notification4);
        }

        // 初始化许可证数据
        if (licenseKeysRepository.count() == 0) {
            // 已激活的许可证示例
            LicenseKeys licenseKeys1 = new LicenseKeys();
            licenseKeys1.setKey("ABCD-1234-EFGH-5678");
            licenseKeys1.setAccountType("Pro");
            licenseKeys1.setActivationStatus(0); // 已激活
            licenseKeys1.setValidDays(30);
            licenseKeys1.setActivationDate(null);
            licenseKeys1.setExpiryDate(null);
            licenseKeys1.setCursorPoolUsageTotal(2000);
            licenseKeys1.setCursorPoolUsageUsed(0);
            licenseKeysRepository.save(licenseKeys1);

            LicenseKeys licenseKeys2 = new LicenseKeys();
            licenseKeys2.setKey("WXYZ-9876-IJKL-5432");
            licenseKeys2.setAccountType("Basic");
            licenseKeys2.setActivationStatus(0);
            licenseKeys2.setValidDays(30);
            licenseKeys2.setActivationDate(null);
            licenseKeys2.setExpiryDate(null);
            licenseKeys2.setCursorPoolUsageTotal(1500);
            licenseKeys2.setCursorPoolUsageUsed(0);
            licenseKeysRepository.save(licenseKeys2);

            // 未激活的许可证示例
            LicenseKeys licenseKeys3 = new LicenseKeys();
            licenseKeys3.setKey("FREE-2468-TEST-1357");
            licenseKeys3.setAccountType("Pro");
            licenseKeys3.setActivationStatus(0);
            licenseKeys3.setValidDays(30);
            licenseKeys3.setActivationDate(null);
            licenseKeys3.setExpiryDate(null);
            licenseKeys3.setCursorPoolUsageTotal(2000);
            licenseKeys3.setCursorPoolUsageUsed(0);
            licenseKeysRepository.save(licenseKeys3);
            


        }

        // 初始化Cursor账号数据
        if (cursorAccountRepository.count() == 0) {
            CursorAccount account1 = new CursorAccount();
            account1.setEmail("account1@example.com");
            account1.setToken("b99e744f-273b-46c5-a7e7-e2c1f0019396");
            cursorAccountRepository.save(account1);

            CursorAccount account2 = new CursorAccount();
            account2.setEmail("account2@example.com");
            account2.setToken("c88f655e-382c-57d6-b8f8-f3d2e0028487");
            cursorAccountRepository.save(account2);

            CursorAccount account3 = new CursorAccount();
            account3.setEmail("account3@example.com");
            account3.setToken("d77g866f-491d-68e7-c9g9-g4e3f1137598");
            cursorAccountRepository.save(account3);
        }
    }
} 